<?php

namespace Controller\Dog;

class Single extends Base {

    public function actionIndex() {
        $this->setCurrentMenuKey('Blind');
        $param = $this->getRouteParams();
        $userId = !empty($param[0]) ? (int) $param[0] : 0;
        if (!$userId) {
            $this->throwException('参数错误');
        }
        $userInfo = $this->getUserDetailInfo($userId);
        if (!$userInfo) {
            $this->throwException('用户不存在');
        }

        $categoryId = $this->getInt('c');
        $categoryInfo = array();
        if ($categoryId) {
            $categoryInfo = \Business\Category::instance()->getCategoryById($categoryId);
            if (!$categoryInfo) {
                $this->throwException('分类信息不存在');
            }
        }

        $pager = new \Lib\Core\Pager();
        $pager->currentPage = $this->getInt('page', 1);
        $articles = \Business\Article::instance()->findArticleByUserId($pager, $userId, $categoryId);
        $count = \Business\Article::instance()->getUserArticleCountByUserId($userId);
        $categoryInfoAndNumbers = \Business\Article::instance()->getHasArticleCategory($userId);
        $this->assign('categoryInfoAndNumbers', $categoryInfoAndNumbers);
        $this->assign('pager', $pager);
        $this->assign('articles', $articles);
        $this->assign('count', $count);
        $this->assign('categoryInfo', $categoryInfo);
        $this->display();
    }
}